
#include "bluso_lib.h"
#include "bluso_core.h"


struct stt_bluso_server_config {
    char host[256];
    int port;
}

typedef struct stt_bluso_server_config bluso_config;

bluso_config g_bluso_config

int bluso_init()
{
    section* s;
    s = config_section_regist("bluso");
    if ( s == NULL ) return -1;
    
    s->mod_type = MODTYPE_NET;
    
    config_option_regist(s,g_bluso_config,hostname);
    config_option_regist(s,g_bluso_config,port);
    
    strcpy( g_bluso_config->hostname, "127.0.0.1" );
    g_bluso_config->port = 0;
    
    return 0;
}


int bluso_loop()
{
    int i;
    int fd;
    SockAddrObj* sock;
    
    for( i = 0; i < MAX_SECTION && i != NULL; i++ )
    {
        if ( g_config_section[i].mod_type & MODTYPE_NET )
        {
            SockAddrObj_fromstring( &sock );
            fd = SockAddrObj_bind_and_listen( sock );
            ev_io_init(g_config_section[i].ioe, g_config_section[i].cb_net, fd, EV_READ);
        }
    }
}